---
title: Query Hub
description: Reusing queries from the community to answer questions on your data
---

import { LinkCard } from '@astrojs/starlight/components';

![Query Hub](https://github.com/julien040/anyquery/raw/main/queries/community-repo.png?raw=true)

Sometimes we want to answer a simple data question, but we don't want (or know how) to write the SQL query. The Query Hub is a collection of SQL queries that you can run on your data

For example, let's say you want the count of commits someone made on a Git repository. You could use a community query to get this information.

## Usage

You can find the full extent of the community repository [here](/queries). If you want to suggest a query, feel free to do so [here](https://github.com/julien040/anyquery/discussions/new?category=ideas) or directly open a pull request on the [repository](
    https://github.com/julien040/anyquery/tree/queries).

<LinkCard title="Community repository" href="/queries"
description="The full list of queries in the community repository."
/>

Once you have found a query you want to run, you can use the `anyquery run` command to execute it. Just copy the command and run it in your terminal.

```bash
anyquery run hello_world
```

Anyquery will take care of asking you for the necessary information to run the query.

You can also run a query from an https URL, or from a local file. For example, to run a query from a URL:

```bash
# Run a query from an https URL
anyquery run https://raw.githubusercontent.com/julien040/anyquery/main/queries/github_stars_per_day.sql
# Run a query from a local file
anyquery run ./queries/github_stars_per_day.sql
```

## Contributing

By contributing to the Query Hub, you can help others answer their data questions, thank you for your help! Queries start with a top-level comment that describes what the query does in TOML. Here is an example:

```sql
/*
title = "GitHub Stars per day"
description = "Discover the number of stars per day for a given repository ordered by date (recent first)"

plugins = ["github"]

author = "julien040"

tags = ["github", "stars", "statistics"]

arguments = [
{title="repository", display_title = "Repository name (owner/repo format)", type="string", description="The repository to fetch stars from (owner/repo)", regex="^[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+$"}
]

 */
SELECT * FROM my_table(@repository)
```

Here is an overview of the fields you can use in the top-level comment:
- `title`: The title of the query. Often, it's formatted as a question.
- `description`: A short description of what the query does to help users find it in the Query Hub.
- `plugins`: An array of plugins that the query uses.
- `author`: The github username of the author.
- `tags`: An array of tags to help users find the query.
- `arguments`: An array of arguments that the query needs to run. Each argument is an object with the following fields:
  - `title`: The title of the argument.
  - `display_title`: The title of the argument displayed to the user.
  - `type`: The type of the argument. It can be `string`, `int`, `float` and `bool`.
  - `description`: A description of the argument.
  - `regex`: A regex to validate the argument.


Each argument in the `arguments` array will be asked to the user when running the query. They will be passed to the query as named parameters. You can specify them in the query using the `@` symbol followed by the argument name.

```sql
SELECT * FROM my_table(@repository)
```

## Reference

You can find the full documentation of the `anyquery run` command [here](/docs/reference/commands/anyquery_run).